Skip to main content
Version: 1.0.16

CREATE FOREIGN DATA WRAPPER

CREATE FOREIGN DATA WRAPPER — Define a new foreign-data wrapper

Synopsis

CREATE FOREIGN DATA WRAPPER name

[ HANDLER handler_function | NO HANDLER ]

[ VALIDATOR validator_function | NO VALIDATOR ]

[ OPTIONS ( option 'value' [, ... ] ) ]

Description

CREATE FOREIGN DATA WRAPPER creates a new foreign-data wrapper. The user who defines the foreign-data wrapper becomes its owner.

The name of the foreign-data wrapper must be unique within the database.

Only superusers can create foreign-data wrappers.

Parameters

name

The name of the foreign-data wrapper to be created.

HANDLER handler_function

handler_function is the name of a previously registered function that will be called to retrieve the execution function for foreign tables. The handler function must take no arguments, and its return type must be fdw_handler.

It is possible to create a foreign-data wrapper without a handler function, but foreign tables using such a wrapper can only be declared, not accessed.

VALIDATOR validator_function

validator_function is the name of a previously registered function that will be called to check the options given to the foreign-data wrapper, as well as options for foreign servers, user mappings, and foreign tables that use the foreign-data wrapper. If no validator function is specified or NO VALIDATOR is specified, options will not be checked at creation time (the foreign-data wrapper may ignore or reject invalid option specifications at runtime, depending on the implementation).

The validator function must accept two arguments: one of type text[], which will contain the array of options stored in the system catalog, and another of type oid, which will be the OID of the system catalog containing the options. The return type is ignored; the function should report invalid options using the ereport(ERROR) function.

OPTIONS ( option 'value' [, ... ] )

This clause specifies options for the new foreign-data wrapper. The allowed option names and values are specific to each foreign-data wrapper and will be validated by the foreign-data wrapper's validator function. Option names must be unique.

Examples

# Create a useless foreign-data wrapper named dummy:

CREATE FOREIGN DATA WRAPPER dummy;

# Create a foreign-data wrapper named file with handler function file_fdw_handler:

CREATE FOREIGN DATA WRAPPER file HANDLER file_fdw_handler;

# Create a foreign-data wrapper named mywrapper with some options:

CREATE FOREIGN DATA WRAPPER mywrapper

OPTIONS (debug 'true');

See Also

ALTER FOREIGN DATA WRAPPER, DROP FOREIGN DATA WRAPPER, CREATE SERVER, CREATE USER MAPPING, CREATE FOREIGN TABLE